package com.eedi.framework.permission.convert;

import cn.hutool.core.util.ObjectUtil;
import com.eedi.framework.permission.controller.org.vo.role.OrgRoleResp;
import com.eedi.framework.permission.controller.org.vo.role.OrgRoleSimpleResp;
import com.eedi.framework.permission.dal.dataobject.OrgRoleDO;
import com.eedi.framework.permission.enums.OrgDataScopeEnum;
import com.eedi.framework.permission.enums.OrgRoleTypeEnum;
import com.eedi.framework.template.dal.dataobject.SysTemplateRoleDO;
import com.eedi.framework.template.enums.SysTemplateDataScopeEnum;
import com.eedi.framework.template.enums.SysTemplateRoleTypeEnum;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.Collection;
import java.util.List;

@Mapper
public interface OrgRoleConvert {

    OrgRoleConvert INSTANCE = Mappers.getMapper(OrgRoleConvert.class);

    OrgRoleSimpleResp convert(OrgRoleDO role);

    OrgRoleDO convert(OrgRoleResp role);



    List<OrgRoleResp> convert(Collection<SysTemplateRoleDO> sysTemplateRoles);

   default OrgRoleResp convert(SysTemplateRoleDO sysTemplateRole){
       if (ObjectUtil.isEmpty(sysTemplateRole)){
           return null;
       }
       OrgRoleResp orgRoleResp=new OrgRoleResp();
       orgRoleResp.setOrgRoleId(sysTemplateRole.getSysTemplateRoleId())
               .setOrgRoleName(sysTemplateRole.getSysRoleName())
               .setOrgRoleCode(sysTemplateRole.getSysRoleCode())
               .setOrgRoleSort(sysTemplateRole.getSysRoleSort())
               .setOrgRoleDataScope(sysTemplateDataScopeToOrgDataScope(sysTemplateRole.getSysRoleDataScope()))
               .setOrgRoleDataScopeDeptIds(sysTemplateRole.getSysRoleDataScopeDeptIds())
               .setOrgRoleStatus(sysTemplateRole.getSysRoleStatus())
               .setOrgRoleType(sysTemplateRoleTypeToOrgRoleType(sysTemplateRole.getSysRoleType()))
               .setOrgRoleRemark(sysTemplateRole.getSysRoleRemark());
       return orgRoleResp;
   }

   default OrgDataScopeEnum sysTemplateDataScopeToOrgDataScope(SysTemplateDataScopeEnum sysRoleDataScope){
       if (ObjectUtil.isEmpty(sysRoleDataScope)){
           return null;
       }
       return OrgDataScopeEnum.getByCode(sysRoleDataScope.getCode());
   }

    default OrgRoleTypeEnum sysTemplateRoleTypeToOrgRoleType(SysTemplateRoleTypeEnum sysTemplateRoleType){
        if (ObjectUtil.isEmpty(sysTemplateRoleType)){
            return null;
        }
        return OrgRoleTypeEnum.getByCode(sysTemplateRoleType.getCode());
    }
}
